<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0
    }

    div {
      text-align: center;
    }

    #box {
      width: 300px;
      height: 300px;
      background-color: cadetblue;

    }

    #box1 {
      width: 200px;
      height: 200px;
      background-color: coral;
    }

    #box2 {
      width: 100px;
      height: 100px;
      background-color: crimson;
    }
  </style>
</head>

<body>
  <div id="box">
    box
    <div id="box1">
      box1
      <div id="box2">
        box2
      </div>
    </div>
  </div>

</body>

<script>
  var boxArr = document.querySelectorAll('div')
  // boxArr[0].onclick = function () {
  //   console.log('点击了box');
  // };
  // boxArr[1].onclick = function () {
  //   console.log('点击了box1');
  // };
  // boxArr[2].onclick = function () {
  //   console.log('点击了box2');
  // };
  boxArr[0].addEventListener('click',function(){
    console.log('点击了box');
  });
  boxArr[1].addEventListener('click',function(){
    console.log('点击了box1');
  });
  boxArr[2].addEventListener('click',function(){
    console.log('点击了box2');
    event.stopPropagation();
  });
//事件的发生  先捕获(找到触发元素)  后冒泡(反馈)
  //事件触发的时候 从根元素 开始找触发事件的这个元素 这个叫事件的捕获
  //事件冒泡 事件的响应 从里往外走

  //e.addEventListener(type,function,true/flase)// 不写默认flase 事件发生在冒泡阶段;
</script>

</html>